<!---
Copyright: (c) 2006 The MachBlog Authors
Authors: Matt Woodward (mpwoodward@gmail.com) & Peter J. Farrell (pjf@maestropublishing.com)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at 

http://www.apache.org/licenses/LICENSE-2.0 

Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language governing permissions and 
limitations under the License.

$Id: UserGateway.cfc 377 2006-05-01 15:53:02Z mpwoodward $

Notes:
--->
<cfcomponent 
	displayname="UserGateway" 
	output="false" 
	extends="UserGateway" 
	hint="UserGateway for MachBlog (MSSQL)">
	
	<cffunction name="init" access="public" output="false" returntype="UserGateway" 
			hint="Constructor for this CFC">
		<cfreturn this />
	</cffunction>
	
	<cffunction name="getUsers" access="public" output="false" returntype="query" 
			hint="Returns a query containing user account information, either active only or all account based on the boolean passed in">
		<cfargument name="getActiveOnly" type="boolean" required="false" default="false" />
		
		<cfset var getUsers = "" />
		
		<cftry>
			<cfquery name="getUsers" datasource="#getDatasource().getDsn()#" 
						username="#getDatasource().getUserName()#" 
						password="#getDatasource().getPassword()#">
				SELECT 	machblog_user.user_id,
						machblog_user.email, 
						machblog_user.first_name, 
						machblog_user.last_name, 
						machblog_user.dt_last_access, 
						machblog_user.is_active, 
						COUNT(machblog_entry.entry_id) AS num_posts 
				FROM 	machblog_user 
				LEFT OUTER JOIN machblog_entry 
					ON machblog_user.user_id = machblog_entry.created_by_id 
				<cfif arguments.getActiveOnly>
				WHERE 	machblog_user.is_active = <cfqueryparam value="1" cfsqltype="cf_sql_bit" />
				</cfif>
				GROUP BY 	machblog_user.user_id, machblog_user.email, machblog_user.first_name, 
							machblog_user.last_name, machblog_user.dt_last_access, 
							machblog_user.is_active 
				ORDER BY last_name, first_name
			</cfquery>
			<cfcatch type="database">
				<cfthrow type="application" message="Database Error" detail="#CFCATCH.Detail#" />
			</cfcatch>
		</cftry>
		
		<cfreturn getUsers />
	</cffunction>
</cfcomponent>
